<script setup>
import { ref, reactive } from 'vue'
const props = defineProps({
  // 表单数据
  data: {
    type: Object,
    default: {}
  },
  formOpt: {
    type: Array,
    default: []
  }
})
const formData = ref(Object.assign({}, props.data))
const emits=defineEmits(['handleForm'])
function handleForm(type) {
  emits('handleForm', type,formData.value)
  
}
</script>

<template>
  <div class="form-wrapper">
    <el-form :model="formData" :inline="true">
      <el-form-item v-for="(item, index) in props.formOpt" :key="index" :label="item.label">
        <el-input v-model.trim="formData[item.prop]" v-if="item.type == 'input'"></el-input>
        <el-select v-model.trim="formData[item.prop]" v-if="item.type == 'select'" placeholder="请选择" size="large" style="width: 200px">
          <el-option
            v-for="obj in item.options"
            :key="obj.value"
            :label="obj.label"
            :value="obj.value"
          />
        </el-select>
        <el-button :type="item.btnType || 'primary'" v-if="item.type == 'button'" @click="handleForm(item.prop)">{{
          item.name
        }}</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<style lang="scss" scoped>
.form-wrapper {
  display: flex;
  justify-content: start;
}
</style>
